home *** CD-ROM | disk | FTP | other *** search
- Path: news.WARWICK.NET!usenet
- From: acorn@warwick.net (Peter Kohlberger)
- Newsgroups: comp.lang.c
- Subject: Re: Resizing Windows using Turbo C++ 3.1
- Date: Fri, 08 Mar 1996 02:24:47 GMT
- Organization: Warwick Online
- Message-ID: <4ho5ne$r37@news1.warwick.net>
- References: <4hiv47$etp@steel.interlog.com>
- NNTP-Posting-Host: t9-03.warwick.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- dsheffie@interlog.com wrote:
-
- >I am writing a windows program, and am trying to get it to resize my window.
-
- >I found the SetWindowPos function in the help files, but it does not seem to work.
- >At the top of the help page, the function is listed as 2.X. Does this mean that this function
- >will not work in 3.X, or only that it was introduced in v 2.1?
-
- >If this is not a valid function in Windows 3.X, can anyone tell me of a similar function
- >which will resize my window?
-
-
- SetWindowPos should wok fine in Win3.1. In fact, it works OK in
- WIN95.
-
- I wrote a program that plays with the window size. It's in three
- files: resize.cpp, resize.h, and resize.rc (for a menu).
- Here they are:
-
- /* file: Resize.cpp */
-
- #include <owl.h>
- #include "resize.h"
-
- // Declare TMyApp, a TApplication descendant
- class TMyApp : public TApplication {
- public:
- TMyApp(LPSTR AName, HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow)
- : TApplication(AName, hInstance, hPrevInstance, lpCmdLine,
- nCmdShow) {};
- virtual void InitMainWindow();
- virtual void InitInstance();
- };
-
- // Declare TMyWindow, a TWindow descendant
- class TMyWindow : public TWindow {
- public:
- TMyWindow(PTWindowsObject, LPSTR);
-
- virtual void CMHalf(RTMessage Msg)
- = [CM_FIRST + CM_HALF];
- virtual void CMDouble(RTMessage Msg)
- = [CM_FIRST + CM_DOUBLE];
- virtual void CMTiny(RTMessage Msg)
- = [CM_FIRST + CM_TINY];
- virtual void CMFull(RTMessage Msg)
- = [CM_FIRST + CM_FULL];
- virtual void CMBigger(RTMessage Msg)
- = [CM_FIRST + CM_BIGGER];
- virtual void CMSmaller(RTMessage Msg)
- = [CM_FIRST + CM_SMALLER];
- };
-
- void TMyWindow::CMHalf(RTMessage) {
-
- RECT desk,curwindow;
- signed int newright,newbottom;
-
- // Get full extent of desktop
- GetWindowRect(GetDesktopWindow(), &desk);
- // Get current window size
- GetWindowRect(HWindow, &curwindow);
-
- //Let's set a lower bound for the window size of 50 X 50
- //However, note Windows will enforce its own minimum
- if ((newright=curwindow.right/2) < 50)
- newright=50;
- if ((newbottom=curwindow.bottom/2) < 50)
- newbottom=50;
-
- //To keep things simple, all resized windows will originate
- // in the upper-left corner of the desktop (the "0, 0," in next
- line)
- SetWindowPos(HWindow, (HWND) NULL, 0, 0,
- newright, newbottom,
- SWP_NOZORDER | SWP_NOACTIVATE);
- }
-
- void TMyWindow::CMDouble(RTMessage) {
-
- RECT desk,curwindow;
- signed int newright,newbottom;
-
- // Get full extent of desktop
- GetWindowRect(GetDesktopWindow(), &desk);
- // Get current window size
- GetWindowRect(HWindow, &curwindow);
-
- //Let's set a upper bound for the window size of full screen
- if ((newright=curwindow.right*2) > desk.right)
- newright=desk.right;
- if ((newbottom=curwindow.bottom*2) > desk.bottom)
- newbottom=desk.bottom;
-
- //To keep things simple, all resized windows will originate
- // in the upper-left corner of the desktop (the "0, 0," in next
- line)
- SetWindowPos(HWindow, (HWND) NULL, 0, 0,
- newright, newbottom,
- SWP_NOZORDER | SWP_NOACTIVATE);
- }
-
- void TMyWindow::CMTiny(RTMessage) {
-
- //To keep things simple, all resized windows will originate
- // in the upper-left corner of the desktop (the "0, 0," in next
- line)
- SetWindowPos(HWindow, (HWND) NULL, 0, 0,
- 50, 50,
- SWP_NOZORDER | SWP_NOACTIVATE);
- }
-
- void TMyWindow::CMFull(RTMessage) {
-
- RECT desk;
-
- // Get full extent of desktop
- GetWindowRect(GetDesktopWindow(), &desk);
-
- //To keep things simple, all resized windows will originate
- // in the upper-left corner of the desktop (the "0, 0," in next
- line)
- SetWindowPos(HWindow, (HWND) NULL, 0, 0,
- desk.right, desk.bottom,
- SWP_NOZORDER | SWP_NOACTIVATE);
- }
-
- void TMyWindow::CMBigger(RTMessage) {
-
- RECT desk,curwindow;
- signed int newright,newbottom;
-
- // Get full extent of desktop
- GetWindowRect(GetDesktopWindow(), &desk);
- // Get current window size
- GetWindowRect(HWindow, &curwindow);
-
- //Let's set a upper bound for the window size of full screen
- if ((newright=curwindow.right+20) > desk.right)
- newright=desk.right;
- if ((newbottom=curwindow.bottom+20) > desk.bottom)
- newbottom=desk.bottom;
-
- //To keep things simple, all resized windows will originate
- // in the upper-left corner of the desktop (the "0, 0," in next
- line)
- SetWindowPos(HWindow, (HWND) NULL, 0, 0,
- newright, newbottom,
- SWP_NOZORDER | SWP_NOACTIVATE);
- }
-
- void TMyWindow::CMSmaller(RTMessage) {
-
- RECT desk,curwindow;
- signed int newright,newbottom;
-
- // Get full extent of desktop
- GetWindowRect(GetDesktopWindow(), &desk);
- // Get current window size
- GetWindowRect(HWindow, &curwindow);
-
- //Let's set a lower bound for the window size of 50 X 50
- //However, note Windows will enforce its own minimum
- if ((newright=curwindow.right-20) < 50)
- newright=50;
- if ((newbottom=curwindow.bottom-20) < 50)
- newbottom=50;
-
- //To keep things simple, all resized windows will originate
- // in the upper-left corner of the desktop (the "0, 0," in next
- line)
- SetWindowPos(HWindow, (HWND) NULL, 0, 0,
- newright, newbottom,
- SWP_NOZORDER | SWP_NOACTIVATE);
- }
-
-
- // Construct a TMyWindow, loading its menu
- TMyWindow::TMyWindow(PTWindowsObject AParent, LPSTR ATitle)
- : TWindow(AParent, ATitle)
- {
- AssignMenu("RESIZECMD"); //see file resize.rc
- }
-
-
- // Construct the TMyApp's MainWindow of type TMyWindow
- void TMyApp::InitMainWindow()
- {
- MainWindow = new TMyWindow(NULL, "Resize example");
- }
-
- /* Initialize each MS-Windows application instance */
- void TMyApp::InitInstance()
- {
- TApplication::InitInstance();
- }
-
- // Run the FileApp
- int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow)
- {
- TMyApp MyApp ("Resize", hInstance, hPrevInstance,
- lpCmdLine, nCmdShow);
- MyApp.Run();
- return MyApp.Status;
- }
- /* End of file: Resize.cpp */
-
- /* file: Resize.h */
- #define CM_HALF 9999
- #define CM_DOUBLE 9998
- #define CM_TINY 9997
- #define CM_FULL 9996
- #define CM_BIGGER 9995
- #define CM_SMALLER 9994
- /* End of file: Resize.h */
-
- /* file: Resize.rc */
- #include "resize.h"
-
- RESIZECMD MENU LOADONCALL MOVEABLE PURE DISCARDABLE
- BEGIN
- POPUP "&Resize"
- BEGIN
- MenuItem "&Half", CM_HALF
- MenuItem "&Double", CM_DOUBLE
- MenuItem "&Tiny", CM_TINY
- MenuItem "&Full", CM_FULL
- MenuItem "&Bigger",CM_BIGGER
- MenuItem "&Smaller",CM_SMALLER
- END
- END
- /* End of file: Resize.rc */
-
- This works for me using Borland Turbo C++ 3.1.
-
- Good luck.
-
- Peter Kohlberger
- acorn@warwick.net
-
-